#import "CTContactVC.h"
#import <ContactsUI/ContactsUI.h>
#import "CTInfoCell.h"
#import "CTRowData.h"
#import "CTSectionData.h"
#import "TJPickerView.h"
#import "CTHeaderSubTitleView.h"
#import "CTContactTableFooter.h"
#import "CTPrivacyVC.h"
#import "NSString+Tools.h"
@interface CTContactVC ()<UITableViewDelegate,UITableViewDataSource,CNContactPickerDelegate>
@property (nonatomic ,strong) NSMutableArray *dataArray;
@property (nonatomic, assign) NSInteger pageIndex;
@property (nonatomic ,strong) UIButton *nextButton;
@property (nonatomic ,strong) CNContact *selctContact;
@property (nonatomic ,strong) NSIndexPath *currentIndexPath;
@property (nonatomic ,strong) NSArray *relationShipPickerData;
@property (nonatomic ,strong) CTContactTableFooter *tableFooter;
@end
@implementation CTContactVC
- (void)zj_viewWillDisappearForIndex:(NSInteger)index {
    [self.view endEditing:YES];
}
- (void)zj_viewWillAppearForIndex:(NSInteger)index {
    self.pageIndex = index;
    NSDictionary *data = @{
        @"navigationRoute" : NSStringFromClass(self.class),
        @"pageIdentity" : kct_page_contact,
        @"elementUniqueIdentifier"  : kct_page_contact,
        @"referenceIdentification" : kct_page_personinfo,
    };
    [CTUploadManager ct_uploadType:CTUploadTypePage data:data];
    NSDictionary *credtiData = @{
        @"tokenUniqueIdentifier"  : returnBeNil(self.pageModel.operationalTaskID),
        @"errorFlag" : kcredit_point_contact,
    };
    [CTUploadManager ct_uploadType:CTUploadTypeCredit data:credtiData];
}
- (void)zj_viewDidLoadForIndex:(NSInteger)index {
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self listConfig];
    [self setUI];
    [self loadPickerSource];
}
- (void)loadPickerSource {
    CTCellElementModel *model = self.pageModel.dataFieldReference[0];
    NSDictionary *paramDic = @{
        @"operationalTaskID" : returnBeNil(self.pageModel.operationalTaskID),
        @"fieldId" : [NSNumber numberWithInteger:model.dataFieldDescription],
    };
    [self.view showLoading];
    [CTBaseRequest getRequestWithMethodName:CTPath(@"/grantingDatas", CTPathTypeCredit, paramDic) parametersDic:paramDic success:^(CTBaseRequest * _Nonnull operation, BOOL isSuccess, id  _Nonnull responseObject) {
        [self.view dismissLoading];
        if (!isSuccess) {
            [self.view showInfoText:(NSString *)responseObject];
        } else {
            NSArray *pickerDatas = [CTPickerDataModel modelArrayWithDictArray:responseObject[@"data"]];
            self.relationShipPickerData = pickerDatas;
        }
    }];
}
- (void)setUI {
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.nextButton];
}
- (void)listConfig{
    CTRowData * relationship1 = [CTRowData new];
    relationship1.editType = CTCellTypeRalationShip1;
    relationship1.placeHolder = @"Please select the relationship with you";
    CTRowData * contact1 = [CTRowData new];
    contact1.editType = CTCellTypeContact1;
    contact1.placeHolder = @"Click + for name";
    CTSectionData *section1 = [[CTSectionData alloc] init];
    section1.sectionTitle = @"Contact1";
    section1.sectionSubTitle = @"Relationship";
    [section1.sectionData addObject:relationship1];
    [section1.sectionData addObject:contact1];
    CTRowData * relationship2 = [CTRowData new];
    relationship2.editType = CTCellTypeRalationShip2;
    relationship2.placeHolder = @"Please select the relationship with you";
    CTRowData * contact2 = [CTRowData new];
    contact2.editType = CTCellTypeContact2;
    contact2.placeHolder = @"Click + for name";
    CTSectionData *section2 = [[CTSectionData alloc] init];
    section2.sectionTitle = @"Contact2";
    section2.sectionSubTitle = @"Relationship";
    [section2.sectionData addObject:relationship2];
    [section2.sectionData addObject:contact2];
    CTRowData * relationship3 = [CTRowData new];
    relationship3.editType = CTCellTypeRalationShip3;
    relationship3.placeHolder = @"Please select the relationship with you";
    CTRowData * contact3 = [CTRowData new];
    contact3.editType = CTCellTypeContact3;
    contact3.placeHolder = @"Click + for name";
    CTSectionData *section3 = [[CTSectionData alloc] init];
    section3.sectionTitle = @"Contact3";
    section3.sectionSubTitle = @"Relationship";
    [section3.sectionData addObject:relationship3];
    [section3.sectionData addObject:contact3];
    [self.dataArray addObject:section1];
    [self.dataArray addObject:section2];
    [self.dataArray addObject:section3];
}
#pragma mark - tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    CTSectionData *sectionModel = self.dataArray[section];
    return sectionModel.sectionData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CTSectionData *sectionModel = self.dataArray[indexPath.section];
    CTRowData *model = sectionModel.sectionData[indexPath.row];
    CTInfoCell *cell = [CTInfoCell cellForTableView:tableView];
    cell.cellType = model.editType;
    if (!beNil(model.placeHolder)) {
        NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:model.placeHolder attributes:
        @{NSForegroundColorAttributeName:[UIColor color999]}];
        cell.contentTF.attributedPlaceholder = attrString;
    }
    switch (model.editType) {
        case CTCellTypeRalationShip1: {
            cell.contentTF.text = self.model.primaryAssociationType.dataCategoryTag;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeContact1: {
            cell.contentTF.text = self.model.primaryContactNumber.telecommunicationDevice;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeName1: {
            cell.contentTF.text = self.model.primaryContactNumber.individualIdentifier;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeRalationShip2: {
            cell.contentTF.text = self.model.secondaryAssociationType.dataCategoryTag;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeContact2: {
            cell.contentTF.text = self.model.secondaryContactNumber.telecommunicationDevice;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeName2: {
            cell.contentTF.text = self.model.secondaryContactNumber.individualIdentifier;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeRalationShip3: {
            cell.contentTF.text = self.model.tertiaryAssociationType.dataCategoryTag;
            cell.contentTF.textColor = [UIColor colorWithHexString:@"#727688"];
        }
            break;
        case CTCellTypeContact3: {
            cell.contentTF.text = self.model.tertiaryContactNumber.telecommunicationDevice;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        case CTCellTypeName3: {
            cell.contentTF.text = self.model.tertiaryContactNumber.individualIdentifier;
            cell.contentTF.textColor = [UIColor blackColor];
        }
            break;
        default:
            break;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return Ratio(54);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CTHeaderSubTitleView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"CTHeaderSubTitleView"];
    CTSectionData *sectionModel = self.dataArray[section];
    header.titleLabel.text = sectionModel.sectionTitle;
    header.subTitleLabel.text = sectionModel.sectionSubTitle;
    return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return Ratio(58);
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footer = [[UIView alloc] init];
    footer.backgroundColor = [UIColor color202020];
    return footer;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (void)toMapCellModel:(CTCreditCellInfo *)cellModel withPickerModel:(CTPickerDataModel *)pickerModel {
    cellModel.attributeCurrentValue = pickerModel.uniqueRecordIdentifier;
    cellModel.hierarchicalParentKey = NSNotFound;
    cellModel.dataCategoryTag = pickerModel.attributeCurrentValue;
    cellModel.statusNarrative = pickerModel.statusNarrative;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.currentIndexPath = indexPath;
    CTSectionData *sectionModel = self.dataArray[indexPath.section];
    CTRowData *model = sectionModel.sectionData[indexPath.row];
    if (self.relationShipPickerData.count == 0) {
        [self loadPickerSource];
    }
    __weak typeof(self) weakSelf = self;
    NSMutableArray *arrM = [NSMutableArray array];
    [self.relationShipPickerData enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CTPickerDataModel *model = obj;
        [arrM addObject:model.attributeCurrentValue];
    }];
    if (!arrM || arrM.count == 0) {
        [self loadPickerSource];
        return;
    }
    switch (model.editType) {
        case CTCellTypeRalationShip1: {
            NSDictionary *data = @{
                @"navigationRoute" : NSStringFromClass(self.class),
                @"pageIdentity" : kct_btn_contact_firstRelation,
                @"elementUniqueIdentifier"  : kct_btn_contact_firstRelation,
            };
            [CTUploadManager ct_uploadType:CTUploadTypeBTN data:data];
            [TJPickerView showStringPickerWithTitle:sectionModel.sectionTitle dataSources:arrM selectValue:arrM.firstObject completion:^(NSString * _Nonnull select) {
                NSInteger index = [arrM indexOfObject:select];
                CTPickerDataModel *pickerModel = [self.relationShipPickerData objectAtIndex:index];
                [weakSelf toMapCellModel:weakSelf.model.primaryAssociationType withPickerModel:pickerModel];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
        case CTCellTypeRalationShip2: {
            NSDictionary *data = @{
                @"navigationRoute" : NSStringFromClass(self.class),
                @"pageIdentity" : kct_btn_contact_spareRelation,
                @"elementUniqueIdentifier"  : kct_btn_contact_spareRelation,
            };
            [CTUploadManager ct_uploadType:CTUploadTypeBTN data:data];
            [TJPickerView showStringPickerWithTitle:sectionModel.sectionTitle dataSources:arrM selectValue:arrM.firstObject completion:^(NSString * _Nonnull select) {
                NSInteger index = [arrM indexOfObject:select];
                CTPickerDataModel *pickerModel = [self.relationShipPickerData objectAtIndex:index];
                [weakSelf toMapCellModel:weakSelf.model.secondaryAssociationType withPickerModel:pickerModel];
                [weakSelf.tableView reloadData];
            }];
        }
            break;
        case CTCellTypeContact1: 
        {
            NSDictionary *data = @{
                @"navigationRoute" : NSStringFromClass(self.class),
                @"pageIdentity" : kct_btn_contact_first_details,
                @"elementUniqueIdentifier"  : kct_btn_contact_first_details,
            };
            [CTUploadManager ct_uploadType:CTUploadTypeBTN data:data];
            CNContactPickerViewController * pickerVC = [[CNContactPickerViewController alloc]init];
            pickerVC.delegate = weakSelf;
            [weakSelf presentViewController:pickerVC animated:YES completion:nil];
        }
            break;
        case CTCellTypeContact2:
        {
            NSDictionary *data = @{
                @"navigationRoute" : NSStringFromClass(self.class),
                @"pageIdentity" : kct_btn_contact_spare_details,
                @"elementUniqueIdentifier"  : kct_btn_contact_spare_details,
            };
            [CTUploadManager ct_uploadType:CTUploadTypeBTN data:data];
            CNContactPickerViewController * pickerVC = [[CNContactPickerViewController alloc]init];
            pickerVC.delegate = weakSelf;
            [weakSelf presentViewController:pickerVC animated:YES completion:nil];
        }
            break;
        case CTCellTypeContact3:
        {
            NSDictionary *data = @{
                @"navigationRoute" : NSStringFromClass(self.class),
                @"pageIdentity" : kct_btn_contact_third_details,
                @"elementUniqueIdentifier"  : kct_btn_contact_third_details,
            };
            [CTUploadManager ct_uploadType:CTUploadTypeBTN data:data];
            CNContactPickerViewController * pickerVC = [[CNContactPickerViewController alloc]init];
            pickerVC.delegate = weakSelf;
            [weakSelf presentViewController:pickerVC animated:YES completion:nil];
        }
            break;
        default:
            break;
    }
}
- (NSArray *)dealPickerDataSource:(NSArray *)dataArray {
    if (dataArray.count == 0) {
        return nil;
    }
    NSMutableArray *arrM = [NSMutableArray array];
    [dataArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CTPickerDataModel *model = obj;
        [arrM addObject:model.attributeCurrentValue];
    }];
    return arrM;
}
#pragma mark - CNContactPickerDelegate
- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
}
- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
    self.selctContact = contact;
    NSString *name = [NSString stringWithFormat:@"%@ %@", contact.givenName, contact.familyName];
    NSArray *phoneNums = contact.phoneNumbers;
    NSMutableArray *contactArray = [NSMutableArray arrayWithCapacity:phoneNums.count];
    for (CNLabeledValue *phone in phoneNums) {
        NSString *name = [NSString stringWithFormat:@"%@%@", contact.familyName, contact.givenName];
        NSString *phoneStr =((CNPhoneNumber *)phone.value).stringValue;
        phoneStr = [phoneStr cleanPhoneNumber];
        [contactArray addObject:phoneStr];
    }
    if (phoneNums.count == 0) {
        NSString *name = [NSString stringWithFormat:@"%@%@", contact.familyName, contact.givenName];
        NSMutableDictionary *contactInfo = [[NSMutableDictionary alloc] init];
        [contactInfo setObject:name forKey:Contact_name];
        [contactInfo setObject:@"" forKey:Contact_mobile];
        [contactArray addObject:contactInfo];
    }
    if (contactArray.count > 1) {
        __weak typeof(self) weakSelf = self;
        [TJPickerView showStringPickerWithTitle:@"" dataSources:contactArray selectValue:contactArray.firstObject completion:^(NSString *select) {
            [weakSelf dealWithName:name phone:select];
        }];
    } else {
        [self dealWithName:name phone:contactArray.firstObject];
    }
}
- (void)dealWithName:(NSString *)name phone:(NSString *)phone {
    CTSectionData *sectionModel = self.dataArray[self.currentIndexPath.section];
    if (self.currentIndexPath.section == 0) {
        self.model.primaryContactNumber.individualIdentifier = name;
        self.model.primaryContactNumber.telecommunicationDevice = phone;
        if (sectionModel.sectionData.count < 3) {
            CTRowData * name = [CTRowData new];
            name.editType = CTCellTypeName1;
            name.placeHolder = @"";
            [sectionModel.sectionData addObject:name];
        }
    } else if (self.currentIndexPath.section == 1) {
        self.model.secondaryContactNumber.individualIdentifier = name;
        self.model.secondaryContactNumber.telecommunicationDevice = phone;
        if (sectionModel.sectionData.count < 3) {
            CTRowData * name = [CTRowData new];
            name.editType = CTCellTypeName2;
            name.placeHolder = @"";
            [sectionModel.sectionData addObject:name];
        }
    } else if (self.currentIndexPath.section == 2) {
        self.model.tertiaryContactNumber.individualIdentifier = name;
        self.model.tertiaryContactNumber.telecommunicationDevice = phone;
        if (sectionModel.sectionData.count < 3) {
            CTRowData * name = [CTRowData new];
            name.editType = CTCellTypeName3;
            name.placeHolder = @"";
            [sectionModel.sectionData addObject:name];
        }
    }
    [self.tableView reloadData];
}
#pragma mark - setting && getting
- (UITableView *)tableView
{
    if (_tableView==nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth-Ratio(20), [UIDevice ct_viewHeight]-Ratio(66) - Ratio(90) - [UIDevice ct_safeBottom]) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = YES;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[CTHeaderSubTitleView class] forHeaderFooterViewReuseIdentifier:@"CTHeaderSubTitleView"];
        _tableView.tableFooterView = self.tableFooter;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
        }
    }
    return _tableView;
}
- (CTContactTableFooter *)tableFooter {
    if (!_tableFooter) {
        _tableFooter = [[CTContactTableFooter alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, Ratio(150))];
    }
    return _tableFooter;
}
- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (UIButton *)nextButton
{
    if (!_nextButton) {
        _nextButton = [[UIButton alloc] init];
        _nextButton.frame = CGRectMake((Ratio(10)), self.tableView.ct_bottom + Ratio(20),kScreenWidth - Ratio(40), Ratio(50));
        [_nextButton setBackgroundColor:[UIColor colorFF6C2E]];
        [_nextButton setTitleColor: [UIColor colorFFF] forState:UIControlStateNormal];
        _nextButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:Ratio(20)];
        [_nextButton setTitle:@"Submit" forState:UIControlStateNormal];
        _nextButton.layer.cornerRadius = Ratio(10);
        _nextButton.layer.masksToBounds = YES;
        [_nextButton addTarget:self action:@selector(nextButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextButton;
}
#pragma mark - Action
- (void)nextFailPoint {
    NSDictionary *credtiData = @{
        @"tokenUniqueIdentifier"  : returnBeNil(self.pageModel.operationalTaskID),
        @"errorFlag" : kpage_contactinfo_nextFailPoint,
    };
    [CTUploadManager ct_uploadType:CTUploadTypeCredit data:credtiData];
}
- (BOOL)checkRelationShip:(NSString *)string {
    if ([string isEqualToString:@"Father"] || [string isEqualToString:@"Mother"] || [string isEqualToString:@"Wife"]
        ) {
        return YES;
    } else {
        return NO;
    }
}
- (void)nextButtonClick {
    if (beNil(self.model.primaryAssociationType.dataCategoryTag) || beNil(self.model.secondaryAssociationType.dataCategoryTag) || beNil(self.model.tertiaryAssociationType.dataCategoryTag)
        || beNil(self.model.primaryContactNumber.telecommunicationDevice) || beNil(self.model.secondaryContactNumber.telecommunicationDevice) || beNil(self.model.tertiaryContactNumber.telecommunicationDevice)) {
        [self.view showText:@"Please complete the information"];
        [self nextFailPoint];
        return;
    }
    if (![self checkRelationShip:self.model.primaryAssociationType.dataCategoryTag] || ![self checkRelationShip:self.model.secondaryAssociationType.dataCategoryTag]) {
        [self.view showText:@"Contact relationship must be spouse, father, mother two items, please check and re-submit"];
        [self nextFailPoint];
        return;
    }
    if ([self.model.primaryAssociationType.dataCategoryTag isEqualToString:self.model.secondaryAssociationType.dataCategoryTag]) {
        [self.view showText:@"Duplicate contact relationship"];
        [self nextFailPoint];
        return;
    }
    if ([self.model.primaryContactNumber.telecommunicationDevice isEqualToString:[CTUserManager shareManager].userModel.wirelessDeviceNumber] || [self.model.secondaryContactNumber.telecommunicationDevice isEqualToString:[CTUserManager shareManager].userModel.wirelessDeviceNumber] || [self.model.tertiaryContactNumber.telecommunicationDevice isEqualToString:[CTUserManager shareManager].userModel.wirelessDeviceNumber]) {
        [self.view showText:@"Please do not enter your own phone number"];
        NSDictionary *credtiData = @{
            @"tokenUniqueIdentifier"  : returnBeNil(self.pageModel.operationalTaskID),
            @"errorFlag" : kpage_contactinfo_selfPhoneNumber,
        };
        [CTUploadManager ct_uploadType:CTUploadTypeCredit data:credtiData];
        return;
    }
    if ([self.model.primaryContactNumber.telecommunicationDevice isEqualToString:self.model.secondaryContactNumber.telecommunicationDevice] || [self.model.primaryContactNumber.telecommunicationDevice isEqualToString:self.model.tertiaryContactNumber.telecommunicationDevice] || [self.model.tertiaryContactNumber.telecommunicationDevice isEqualToString:self.model.secondaryContactNumber.telecommunicationDevice]) {
        [self.view showText:@"The contact number is repeated. Select another contact"];
        NSDictionary *credtiData = @{
            @"tokenUniqueIdentifier"  : returnBeNil(self.pageModel.operationalTaskID),
            @"errorFlag" : kpage_contactinfo_phoneDuplicate,
        };
        [CTUploadManager ct_uploadType:CTUploadTypeCredit data:credtiData];
        return;
    }
    _contactArray = [NSMutableArray array];
    NSDictionary *contact1 = @{
        @"associationLink" : returnBeNil(self.model.primaryAssociationType.dataCategoryTag),
        @"notedName" : returnBeNil(self.model.primaryContactNumber.individualIdentifier),
        @"communicationNumber" : returnBeNil(self.model.primaryContactNumber.telecommunicationDevice),
    };
    NSDictionary *contact2 = @{
        @"associationLink" : returnBeNil(self.model.secondaryAssociationType.dataCategoryTag),
        @"notedName" : returnBeNil(self.model.secondaryContactNumber.individualIdentifier),
        @"communicationNumber" : returnBeNil(self.model.secondaryContactNumber.telecommunicationDevice),
    };
    NSDictionary *contact3 = @{
        @"associationLink" : returnBeNil(self.model.tertiaryAssociationType.dataCategoryTag),
        @"notedName" : returnBeNil(self.model.tertiaryContactNumber.individualIdentifier),
        @"communicationNumber" : returnBeNil(self.model.tertiaryContactNumber.telecommunicationDevice),
    };
    [_contactArray addObject:contact1];
    [_contactArray addObject:contact2];
    [_contactArray addObject:contact3];
    if (!self.tableFooter.protocolButton.selected) {
        __weak typeof(self) weakself = self;
        TJAlertView *aAlertView = [TJAlertView alertWithTitle:@"" subTitle:@"Please read Privacy Policy and Contact Information Statement to understand how we collect, use and store your data to understand the responsibilities and obligations of each party, and other detailed information." clickTitle:@"Privacy Policy" clickSecond:@"Contact Information Statement" click:^(NSString * _Nonnull title) {
            NSString *url = [NSURL fullUrlStringForWeb:[CTEnvironmentManager shareManager].privacyPolicyUrl];
            CTPrivacyVC *webVc = [[CTPrivacyVC alloc] initWithTitle:@"" gotoUrl:url];
            [webVc showLeftSingleBack];
            [self.navigationController pushViewController:webVc animated:YES];
        }];
        TJAlertViewAction *aCancelAction = [TJAlertViewAction actionWithTitle:@"Refused" titleColor:[UIColor color161616] backGroudColor:[UIColor whiteColor] handler:nil];
        TJAlertViewAction *aSureAction = [TJAlertViewAction actionWithTitle:@"I have read and accept" titleColor:[UIColor colorFF6C2E] backGroudColor:[UIColor whiteColor] handler:^(TJAlertViewAction *action) {
            weakself.tableFooter.protocolButton.selected = !weakself.tableFooter.protocolButton.selected;
        }];
        [aAlertView doAddAction:aCancelAction];
        [aAlertView doAddAction:aSureAction];
        [aAlertView doShowAlertView];
        return;
    }
    NSDictionary *credtiData = @{
        @"tokenUniqueIdentifier"  : returnBeNil(self.pageModel.operationalTaskID),
        @"errorFlag" : kcredit_point_contact,
    };
    [CTUploadManager ct_uploadType:CTUploadTypeCredit data:credtiData];
    if (self.submitClickBlock) {
        self.submitClickBlock();
    }
}
- (CTContactModel *)model {
    if (!_model) {
        _model = [[CTContactModel alloc] init];
    }
    return _model;
}
@end
